package practice04;

import java.io.*;
import java.net.Socket;

/**
 * @author Administrator
 * @version V1.0
 * @ProjectName:IntelliJ IDEA
 * @PackageName: PACKAGE_NAME
 * @ClassName: practice04.ClientThread
 * @Description: TODO(这里用一句话描述这个类的作用)
 * @date 2019/12/30 20:16
 * @Copyright 大牛版板所有
 */
public class ClientThread implements Runnable {
    Socket client = null;

    public ClientThread(Socket client) {
        this.client = client;
    }



    @Override
    public void run() {
        InputStream reader = null;
        DataOutputStream writer = null;
        try {
            reader = client.getInputStream();
            writer = new DataOutputStream(new FileOutputStream("chapter05\\file\\text.txt"));
            byte[] bytes = new byte[10240];
            int len = 0;
            while ((len = reader.read(bytes)) != -1){
                writer.write(bytes,0,len);
                writer.flush();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            if (client != null){
                try {
                    client.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
